package com.zking.forward.index;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/checkCodeServlet")
public class CheckCodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //处理请求的编码，解决中文乱码
        request.setCharacterEncoding("utf-8");
        //处理响应的编码 ，解决中文乱码
        response.setContentType("text/html;charset=utf-8");

        System.out.println("CheckCodeServlet===进来");
        PrintWriter out = response.getWriter();
        System.out.println("成功进入CheckLoginServlet的ajax检查servlet的post");

        //先拿到请求的参数--用户输入的验证码
        String code_input = request.getParameter("code");
        System.out.println("code_input==="+code_input);
        HttpSession session = request.getSession();
        String code_rand = (String)session.getAttribute("code");
        System.out.println("code_rand==="+code_rand);
        if (code_input.equalsIgnoreCase(code_rand)){
            out.print("true");
        }else{
            out.print("false");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
